package com.zm.test.devView;

import java.util.List;

/**
 * 制作尚灵电量仪视图表格
 * 
 */
public class CreateTableView {
	public static void main(String[] args) {

		String excelPath = "F:\\work\\采集设计文档-zm\\";

		String excelFile = "suningPdcView.xls";

		excelFile = excelPath + excelFile;

		StringBuffer sb = new StringBuffer();

		try {

			GraphTableExcelFactory factory = new GraphTableExcelFactory(excelFile);

			List<GraphTable> graphTableList = factory.getAllGraphTable();
			for (GraphTable graphTable : graphTableList) {
				// 指标
				List<List<String>> attrsList = graphTable.getAttrs();
				//
				List<Integer> coordxList = graphTable.getCoordxs();
				//
				List<Integer> coordyList = graphTable.getCoordys();

				for (int i = 0; i < attrsList.size(); i++) {
					List<String> rowAttr = attrsList.get(i);
					int y = coordyList.get(i);

					for (int j = 0; j < rowAttr.size(); j++) {
						String val = rowAttr.get(j);
						int x = coordxList.get(j);

						// 拆为objId和指标
						String attrs[] = val.split("A");
						if (attrs.length != 2) {
							throw new Exception("shell " + graphTable.getPdcName() + " cell(" + i + "," + j
									+ ") format error,[" + val + "], need ex:10024001A007");
						}
						String objId = attrs[0];
						String attr = attrs[1];

						sb.append("<graph>\n");
						sb.append("<shape>rect</shape>\n");
						sb.append("<coords>").append(x).append(",").append(y).append(",")
								.append(graphTable.getCellWidth()).append(",").append(graphTable.getCellHeight())
								.append("</coords>\n");

						sb.append("<obj>").append(objId).append("</obj>\n");
						sb.append("<attr>A").append(attr).append("</attr>\n");
						sb.append("<showLabel>0</showLabel><render>text</render><showUnit>0</showUnit><binding>attr</binding>\n");

						sb.append("</graph>\n");

					}
				}
			}

			System.out.println(sb.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	// <graph>
	// <shape>rect</shape>
	// <coords>543,308,100,20</coords>
	// <obj>1000093</obj>
	// <objname>PDU4A-1</objname>
	// <attr>A008</attr>
	// <attrname>电流2</attrname>
	// <showLabel>0</showLabel><render>text</render><showUnit>0</showUnit>
	// <unit>A</unit>
	// <binding>attr</binding>
	// </graph>

}
